package be.ad.coffeebreak.web;

import be.ad.coffeebreak.web.commands.*;
import org.apache.log4j.Logger;

/**
 * A factory for creating commands from uris.
 *
 * @author Stefan Bangels
 */
public final class CommandFactory {

    private final Logger logger = Logger.getLogger(getClass());

    private ServiceLocator serviceLocator;

    /**
     * Set the service locator.
     *
     * @param serviceLocator the service locator
     */
    public void setServiceLocator(ServiceLocator serviceLocator) {
        this.serviceLocator = serviceLocator;
    }

    /**
     * Create a command for the specified uri.
     *
     * @param uri the uri
     * @return the command
     */
    public Command createCommand(String uri) {
        logger.info("lookup command for uri: " + uri);
        if ("".equals(uri) || "/".equals(uri) || "/dashboard".equals(uri)) {
            return new DashboardCommand(serviceLocator);
        } else if ("/projects".equals(uri)) {
            return new ProjectsListCommand(serviceLocator);
        } else if ("/projects-details".equals(uri)) {
            return new ProjectDetailsCommand(serviceLocator);
        } else if ("/projects-hours".equals(uri)) {
            return new ProjectHoursCommand(serviceLocator);
        } else if ("/user-details".equals(uri)) {
            return new UserDetailsCommand(serviceLocator);
        } else if ("/reports".equals(uri)) {
            return new ReportsCommand(serviceLocator);
        } else if ("/help".equals(uri)) {
            return new HelpCommand(serviceLocator);
        } else if ("/logout".equals(uri)) {
            return new LogoutCommand(serviceLocator);
        }
        return null;
    }

}
